﻿#ifndef ABSTRACTBLOCK_H
#define ABSTRACTBLOCK_H

#include <QString>
#include <QPainter>
#include <QMargins>
#include <QGraphicsItem>

#include "FlowChart_Global.h"

namespace CVV
{

namespace FlowChart
{

#define SetNewPen(penW)         \
   {                             \
    QColor col(0x12,0x96,0xdb); \
    oldP =  canvas->pen(); \
    QPen pe(col);               \
    pe.setWidthF(penW);         \
    canvas->setPen(pe);         \
   }                            \

#define UseOldPen               \
    canvas->setPen(oldP);       \


class  QBlock ;
/**
 * @brief 绘制块壮类接口类
 *
 */


class AbstractBlock
{
public:
     AbstractBlock();
     virtual ~AbstractBlock();
     /**
      * @brief paint 绘制bock 形状
      * @param canvas 画板
      * @param fontSizeInPoints 字体大小
      */
     virtual void paint(QPainter *canvas) = 0;

     /**
      * @brief getBlockDom
      * @return 返回区域块Dom xml结构
      */
     static QString getBlockDom();
     /**
      * @brief drawBottomArrow
      * @param canvas 画板
      * @param aPoint 起点
      * @param aSize 箭头大小
      */
     static void drawBottomArrow(QPainter *canvas, const QPointF & aPoint, const QSizeF & aSize);

     /**
      * @brief drawRightArrow
      * @param canvas 画板
      * @param aPoint 起点
      * @param aSize 箭头大小
      */
     static void drawRightArrow(QPainter *canvas, const QPointF & aPoint, const QSizeF & aSize);

     /**
      * @brief 以下外属性get set
      * @return
      */

     QString name() const;
     void setName(const QString &name);

     QRect postion() const;
     void setPostion(const QRect &postion);

     QMargins margin() const;
     void setMargin(const QMargins &margin);

     double zoom() const;
     void setZoom(double zoom);

     int penWidth() const;
     void setPenWidth(int penWidth);

     QList<QBlock *> getBranchItem() const;
     void setBranchItem(const QList<QBlock *> &branchItem);

     QString runState() const;
     void setState(const QString& state);

     //设置引用状态
     int getReferenceStatus();
     void setReferenceStatus(int rState);

private:
     /**
     * @brief 区域块名称
     */
     QString m_name;
     /**
      * @brief 区域块位置
      */
     QRect   m_postion;
     /**
      * @brief 区域块边距
      */
     QMargins m_margin;
     /**
      * @brief 区域块放大比例
      */
     double m_zoom;
     /**
      * @brief 区域块画笔宽度
      */
     int m_penWidth;
     /**
      * @brief 分支项点
      */
     QList<QBlock*> m_branchItem;

     /**
      * @brief 运行状态
      */
     QString m_runState;

     /**
      * @brief 引用状态
      * -1:被别的节点引用，且又不引用当前选中节点
      * 0:未被别的节点引用，且又不引用当前选中节点
      * 1:未被别的节点引用，但是引用了当前选中节点
      * 2:被别的节点引用，又引用了当前选中节点
      */
     int m_iReferenceStatus{-1};


public:
     static float m_aScale;
     static float m_bScale;
     static float m_lineScale;
     bool m_isExpand{true};                                     // 默认展开
     QPen oldP;
     QColor m_backgroundColor{"#D2E9FF"};
     QColor m_collapseBgColor{"#FFA448"};                       // 折叠区域背景色
     QColor m_runSuccessColor{"#00DB00"};
     QColor m_runErrorColor{Qt::red};
     QList<QColor> m_unReferencedColor{"#FFA500", "#8B008B", "#000080"};
};

}

}
#endif // IBLOCK_H
